public class GuiBotReadThread extends Thread
{
	SocketClient socket;
	String msg;
	GuiBot gui;
	String[] msgTable;
	String lastMsg;
	boolean check=false;
	boolean canMove=false;
	GuiBotReadThread(SocketClient s,GuiBot gui)
	{
		this.socket=s;
		this.gui=gui;
	}
	public void run()
	{
		while(!isInterrupted())
		{
			try 
			{
				GuiBotReadThread.sleep(200);
			} 
			catch (InterruptedException e) 
			{				
				//e.printStackTrace();
			}
			if(socket.connected==true)
			{
				String clientCommand = "";
				clientCommand = socket.msg.msg;
				
				if(clientCommand!=null)
				{
	            	msgTable=clientCommand.split(":");
	            	if(msgTable[0].equalsIgnoreCase("C"))
	            	{
	            		gui.bCard1.setText(msgTable[1]);
	            		gui.bCard2.setText(msgTable[2]);
	            		gui.bCard3.setText(msgTable[3]);
	            		gui.bCard4.setText(msgTable[4]);
	            	}
	            	else if(msgTable[0].equalsIgnoreCase("MB"))
	            	{
	            		int value = Integer.parseInt(msgTable[1]);
	            		gui.maxBet=value;
	            	}
	            	else if(msgTable[0].equalsIgnoreCase("M"))
	            	{
	            		if(msgTable[1].equalsIgnoreCase("FALSE"))
	            			canMove=false;
	            		else if(msgTable[1].equalsIgnoreCase("TRUE"))
	            			canMove=true;
	            		if(!(msgTable[1].equalsIgnoreCase(lastMsg)))
	            		{	
	            			if(!(msgTable[1].equalsIgnoreCase("FALSE") || msgTable[1].equalsIgnoreCase("TRUE")))
	            			{
	            				gui.taMsg.setText(gui.taMsg.getText()+"\n"+msgTable[1]);
	            				lastMsg=msgTable[1];
	            			}
	            			else if((msgTable[1].equalsIgnoreCase("FALSE") || msgTable[1].equalsIgnoreCase("TRUE")))
	            			{
	            				lastMsg=msgTable[1];
	            			}
	            			
	            		}
	            		if(msgTable[1].equalsIgnoreCase("FALSE"))
	            			canMove=false;
	            		else if(msgTable[1].equalsIgnoreCase("TRUE"))
	            			canMove=true;
	            		if(canMove==false)
	            			continue;
	            		if(lastMsg.equalsIgnoreCase("You can change some cards now") || msgTable[1].equalsIgnoreCase("You can change some cards now"))
	            		{
	            			socket.sendMsg("CHANGE:0:0:0:4");
	            		}
	            		else if(lastMsg.equalsIgnoreCase("Your turn."))
	            		{;
	        				String bankRollText = gui.tfBet.getText();
	        				int bankRoll = Integer.parseInt(bankRollText);
	        				if(gui.maxBet==0&&check==false)
	            			{
	        					socket.sendMsg("BET:"+40);
	        					check=true;
	            			}
	        				else if(gui.maxBet+150<bankRoll)
	            			{
	            				socket.sendMsg("CALL");
	            			}
	            			else if(gui.maxBet+150<250)
	            			{
	            				socket.sendMsg("RAISE:"+20);
	            			}
	            			else
	            			{
	            				socket.sendMsg("FOLD");
	            			}
	            		}
	            		
	            	}
	            	else if(msgTable[0].equalsIgnoreCase("B"))
	            	{
	            		gui.tfBankRoll.setText(msgTable[1]);
	            	}
				}
			}	
		}
	}

}
